package com.chen.mapper;

import com.chen.pojo.Emp;
import com.chen.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    //--------------------原始分页操作---------
    /*
     * 查询总记录数
     */
//    @Select("select count(*) from emp e left join dept d on e.dept_id=d.id")
//    public Long count();
    /*
     * 分页查询
     */
//    @Select("select e.*,d.name deptName from emp e left join dept d " +
//            "on e.dept_id=d.id order by d.update_time desc limit #{start},#{pageSize} ")
//    public List<Emp> list(Integer start,Integer pageSize);
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id order by d.update_time desc ")

     List<Emp> list(EmpQueryParam empQueryParam);
    @Options(useGeneratedKeys = true,keyProperty = "id")//获得生成的主键 -- 主键返回
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time)" +
    "values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);


    Emp getInfoById(Integer id);


    void updateInfo(Emp emp);

    /*
     * 统计每个部门的员工数量
     */

    List<Map<String,Object>> countEmpJobData();

    @Select("select if(gender=1,'男性员工','女性员工') as name, count(*) as value from emp group by gender ;")
    List<Map<String, Object>> countEmpGenderData();

    @Select("select * from emp")
    List<Emp> findall();

    @Select("select count(*) from emp where dept_id=#{id}")
    Integer countEmpByDeptId(Integer id);

    @Select("select id,username,name from emp where username=#{username} and password=#{password}")
    Emp selectByUsernameAndPassword(Emp emp);
}
